<template>
	<div class="homenewzone">
		<img class="newzonebg"  v-if="config.config.state==='1' || config.config.state === undefined" :src="arraydata.publicityPicture||'static/image/demo1.png'" @click='jumpEvent()' />
	</div>
</template>

<script>
	import handlePathSpecial from '../../utils/lxn/handlePathSpecial';
	import { NAVIGATE } from "../../config/postMessage-types";
	import {mapGetters} from "vuex";
	export default {
		props: {
			dataList: {
				type: Array,
				default: () => []
			},
			config: {
				type: Object,
				default: ()=>{}
			},
		},
		data() {
			return {
                arraydata: {},
			}
		},
		watch:{
			dataList(data){
				this.onedata()
			}
		},
		methods: {
			onedata() {
				if(this.dataList) {
					this.arraydata = this.dataList[0] ? this.dataList[0] : {};
				}
			},
			jumpEvent() {
                if (!this.arraydata.extendField) return;
                if(!this.isApp){
					// var urldata = JSON.parse(this.arraydata.extendField).url.path
					var urldata = handlePathSpecial(this.arraydata.extendField)
					if(urldata) {
						this.$router.push({
							path : urldata
							// name: "MiddleWare",
							// params: {
							// 	pageName: urldata
							// }
						})
					}
                }else if(this.isApp){
					var urldata = JSON.parse(this.arraydata.extendField).url
					if(!urldata){return}
					if (urldata.valueArray[0] == '商品详情页面' ) {
						this.gotornpage('Detail', urldata.path.split("=")[1])
					} else if (urldata.valueArray[0] == '分类页面'){
						this.gotornpage('GoodsClassify', urldata.path.split("=")[1])
					} else if (urldata.valueArray[0] == '其他页面') {
						if(urldata.path == 'IntegralBuy') {
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							}else{
								this.gotornpage(urldata.path)
							}
						}else if(urldata.path == 'Coupons'){
							this.gotornpage('CouponsAcquire')
						} else if (urldata.path == 'buyGiftCard') {
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							} else{
								this.gotornpage('BuyGiftCard')
							}
						} else if(urldata.path == 'foodChecked'){
							if(this.hasUserInfo ===0) {
								this.gotornpage('Login')
							}
							else{
								this.gotornpage('FoodCheck')
							}
						} else if(urldata.path == 'prize_card'){
								if(this.hasUserInfo ===0) {
									this.gotornpage('Login')
								} else {
								this.$router.push({
									name: "MiddleWare",
									params: {
										pageName: urldata.path
									}
								})
							}
						} else if(urldata.path == 'integral'){
								if(this.hasUserInfo ===0) {
									this.gotornpage('Login')
								} else {
									this.$router.push({
										name: "MiddleWare",
										params: {
											pageName: urldata.path
										}
									})
							}
						} else if(urldata.path == 'login'){
							this.gotornpage('Login')
						} else if(urldata.path == 'register'){
							this.gotornpage('Regrester')
						} else {
							this.$router.push({
								name: "MiddleWare",
								params: {
									pageName: urldata.path
								}
							})
						}
					}
                }
			},
			gotornpage(page, code) {
				let params = {}
				if(page=='Detail'){
					params = {
						screen: page,
						params:{
							goodsCode: code
						}
					}
				}else if(page=='GoodsClassify'){
					params = {
						screen: page,
						params:{
							classCode: code
						}
					}
				}else{
					params = {
						screen: page,
					}
				}
				let goBackIns = {
					type: NAVIGATE,
					params: params
				}
				window.postMessage(JSON.stringify(goBackIns));
			}
		},
		computed: {
			isApp() {
				return window.isApp;
			},
			...mapGetters('wxh', [
                'userInfo'
            ]),
            hasUserInfo() {
                return Object.keys(this.userInfo).length;
            },
		},
		mounted() {
            this.onedata()
		},
	}
</script>

<style>
	.homenewzone {
		background-color: #fff;
		/*padding: 0.75rem 0rem;*/
		/* padding: 0.75rem; */
	}
	
	.newzonebg {
		margin: 0 auto;
		width: 100%;
		/*height: 3.5rem;*/
		/*border-radius: 4rem;*/
	}
</style>